package com.Sinewecology.EntropySMS;

import java.io.IOException;
import java.util.ArrayList;


import com.Sinewecology.SendMessage.MobileMsgDataBean;
import com.entrogy.dao.MessageMapper;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

public class SMS {
	private static final Logger logger = LoggerFactory.getLogger(SMS.class);
	private static int smsAppId = 1400145249;
	private static String smsAppKey = "332e398750ffe58355866bc9410e14c7";

	public static String SendSmsToUser(MobileMsgDataBean msg) throws JSONException, HTTPException, IOException {
		int templateId = Integer.parseInt(msg.getTemplateId());
		String phone = msg.getPhoneNumber();
		ArrayList<String> params = msg.getKeyword();
		SmsSingleSender ssender = new SmsSingleSender(smsAppId, smsAppKey);
		SmsSingleSenderResult result = ssender.sendWithParam("86", phone, templateId, params, "", "", "");
		logger.info("短信发送" + phone + "结果:" + result.errMsg);
		return result.errMsg;
	}
}
